package com.example.carrierapp.ui.adapter;

import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.example.carrierapp.ui.main.dispatch.no.DispatchNoFragment;
import com.example.carrierapp.ui.main.dispatch.yes.DispatchYesFragment;

public class DispatchMainAdapter extends FragmentPagerAdapter {
    String[] mTitles;
    DispatchNoFragment mDispatchNoFragment;
    DispatchYesFragment mDispatchYesFragment;

    public DispatchMainAdapter(FragmentManager fm,String[] titles) {
        super(fm);
        mTitles = titles;
    }

    @Override
    public Fragment getItem(int position) {
        Fragment fragment = null;
        switch (position) {
            case 0:
                if (mDispatchNoFragment == null) {
                    mDispatchNoFragment = DispatchNoFragment.Companion.newInstance();
                }
                fragment = mDispatchNoFragment;
                break;
            case 1:
                if (mDispatchYesFragment == null) {
                    mDispatchYesFragment = DispatchYesFragment.Companion.newInstance();
                }
                fragment = mDispatchYesFragment;
                break;
        }

        return fragment;
    }

    @Override
    public int getCount() {
        return mTitles.length;
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return mTitles[position];
    }
}
